package com.ask.result;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> implements Serializable {
    private Integer code;
    private String msg;
    private T data;


    public static <T> Result<T> success(T data) {
        return new Result<>(1, null, data);
    }

    public static <T> Result<T> success() {
        return new Result<>(1, "success", null);
    }

    public static <T> Result<T> success(T data, String message) {
        return new Result<>(1, message, data);
    }

    public static <T> Result<T> error(String message) {
        Result result = new Result();
        result.code = 0;
        result.msg = message;
        return result;
    }
}
